#!/bin/bash

# 定义截取函数
extract_between() {
    local file="$1"
    local start_marker="$2"
    local end_marker="$3"
    
    # 参数检查
    if [[ -z "$file" || -z "$start_marker" || -z "$end_marker" ]]; then
        echo "Usage: extract_between <file> <start_marker> <end_marker>"
        return 1
    fi
    
    # 检查文件是否存在
    if [[ ! -f "$file" ]]; then
        echo "Error: File '$file' not found"
        return 1
    fi
    
    # 使用sed截取begin和end之间的内容（包含begin和end行）
    sed -n "/$start_marker/,/$end_marker/p" "$file"
}

# 使用方法 extract_between “文件名” “begin” “end”
extract_between $1 $2 $3
